$(function () {
	projectList(1);
});
//搜索
function projectList(init){
	if(init==1)$("#searchForm .pageNum").val(1);	
	JY.Model.loading();
	JY.Ajax.doRequest("searchForm",jypath +'/estate/project/list',null,function(data){
		var obj = $("#permitBtnJson").html();
		var permitBtn=new Array();
		 $("#baseTable tbody").empty();
	     //分页对象
    	 var page=data.obj;
    	 //权限按钮
    	 var btnObj=eval(obj);
 		for(var i=0;i<btnObj.length;i++){
 			if(btnObj[i].permission=='estate:project:edit'){
 				permitBtn.push({name:"修改",btnFun:"projectEdit",icon:"icon-edit color-blue"});
 			}else if(btnObj[i].permission=='estate:project:delete'){
 				permitBtn.push({name:"删除",btnFun:"projectDel",icon:"icon-remove-sign color-red"});
 			}/*else if(btnObj[i].permission=='estate:sub:bind'){
 				permitBtn.push({name:"绑定认购回款",btnFun:"projectBind",icon:"icon-zoom-in color-purple"});
     		}*/
 		}
    	 //数据集合
    	 var results=page.rows;
    	 //分页数据
     	 var pageNum=page.pageNumber,pageSize=page.pageSize,totalRecord=page.total;
    	 var html="";
    	 var menuId=$("#menuId").val();
		 if(results!=null&&results.length>0){
    		 var leng=(pageNum-1)*pageSize;//计算序号
    		 for(var i = 0;i<results.length;i++){
        		 var l=results[i];
        		 html+="<tr>";
        		// html+="<td class='center'><label> <input type='checkbox' name='ids' value='"+l.id+"' class='ace' /> <span class='lbl'></span></label></td>";
        		 html+="<td class='center hidden-480'>"+(i+leng+1)+"</td>";
        		 html+="<td class='center'><a href='"+jypath+"/estate/treeComponent/index?projectId="+l.id+"&menuId="+menuId+"'>"+JY.Object.notEmpty(l.projectName)+"</a></td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.premisesCount)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.buildingCount)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.unitCount)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.roomCount)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.areaFullName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.projectTypeName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.generalManagerName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.projectLeaderName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.saleLeaderName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.fieldLeaderName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.maLeaderName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.financeLeaderName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.areaLeaderName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.areaManagerName)+"</td>";
        		 html+="<td class='center'>"+JY.Object.notEmpty(l.updateTimeStr)+"</td>";
        		 html+=JY.Tags.setFunction(l.id,permitBtn);
        		 html+="</tr>";		 
        	 } 
    		 $("#baseTable tbody").append(html);
    		 JY.Page.setPage("searchForm","pageing",pageSize,pageNum,totalRecord,"projectList");
    	 }else{
    		html+="<tr><td colspan='18' class='center'>没有相关数据</td></tr>";
    		$("#baseTable tbody").append(html);
    		$("#pageing ul").empty();//清空分页
    	 }
    	 JY.Model.loadingClose();
	 });
	 JY.Model.loadingClose();
}
//跳转新增
function projectToAdd(){
   var url=jypath+"/estate/project/toAdd";
   window.location.href=url;
}
//修改
function projectEdit(id){
	var url=jypath+"/estate/project/toAdd?id="+id;
	window.location.href=url;
}
//查看
//function projectView(id){
//	var url=jypath+"/estate/project/detail?id="+id;
//	window.location.href=url;
//}
//删除
function projectDel(id){
	JY.Model.confirm("请再次确认是否删除该项目？",function(){	
		JY.Ajax.doRequest(null,jypath+'/estate/project/delete',{id:id},function(data){
			JY.Model.info(data.resMsg,function(){projectList(1);});
		});
	});
}

function projectBind(id){
    layer.confirm('是否确认开启认购后收签约款功能?', {
        btn: ['确认','取消'] //按钮
    }, function(){
        $.ajax({
            type: 'post',
            url: jypath+"/estate/project/bindReceivables",
            data: {
                projectId:id
            },
            dataType:'json',
            success: function(obj){
                if(obj.res=="0"){
                    layer.alert("绑定失败");
                }else{
                    layer.alert("绑定成功");
                }
            }
        });
    });
}

function regionSelectChange(obj,initId){
	var parentId=$(obj).val();
	if(parentId=="-1"){
		var option='<option value="-1" >请选择城市 </option>';
		$("#"+initId).html(option);
		return;
	}
	$.ajax({
		type: 'post',
        url: jypath+"/system/area/findAreaByParentId",
	    data: {
	    	parentId:parentId
	    },
	    dataType:'json',
	    success: function(res){
	    	$("#"+initId).empty();
	    	var list=res.obj;
	    	var option='<option value="-1" >请选择城市 </option>';
    		$.each(list, function(index, row) {
    			option=option+'<option value="'+row.id+'">'+row.areaName+'</option>';
    		});
    		$("#"+initId).html(option);
	    	
	    }
	});
}





